﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Windows.Forms;
using Microsoft.SqlServer.Management.Smo;
using Microsoft.SqlServer.Management.Nmo;
using Microsoft.SqlServer.Management.Common;
using Microsoft.SqlServer.Management.Trace;

namespace Entity
{
    public class LOAIDETAI
    {
        private String LOAIDT;
        private int SOTC;

        public int soTC
        {
            get { return SOTC; }
            set { SOTC = value; }
        }
        /// <summary>
        /// /
        /// </summary>
        public String loaiDT
        {
            get { return LOAIDT; }
            set { LOAIDT = value; }
        }
        /// <summary>
        /// 
        /// </summary>
        DataBaseAccess dataBaseAccess = new DataBaseAccess();

        public void hienthi_LoaiDeTai(DataGridView dtgLDT)
        {
            try
            {
                DataTable dataTable = new DataTable();
                dataTable = dataBaseAccess.getDataTable("SELECT * FROM LOAIDETAI");
                dtgLDT.DataSource = dataTable;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Loi Hien Thi Loai De Tai \n" + ex.Message);
            }
        }

        public void them_LoaiDeTai(LOAIDETAI loaidetai)
        {
            try
            {
                String excuteString = "INSERT INTO LOAIDETAI VALUES('" + loaidetai.loaiDT + "',"
                                                                        + loaidetai.soTC + ")";
                dataBaseAccess.excuteNonQuery(excuteString);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Loi Them Vao Loai De Tai\n " + ex.Message);
            }
        }

        public void sua_LoaiDeTai(LOAIDETAI loaidetai)
        {
            try
            {
                String excuteString = "UPDATE LOAIDETAI SET SOTC = " + loaidetai.soTC +
                                                 " WHERE LOAIDT ='" + loaidetai.loaiDT + "'";

                dataBaseAccess.excuteNonQuery(excuteString);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Loi Sua Loai De Tai\n " + ex.Message);
            }
        }

        public void xoa_LoaiDeTai(String loaidetai)
        {
            try
            {
                String excuteString = "DELETE FROM LOAIDETAI WHERE LOAIDT ='" + loaidetai + "'";

                dataBaseAccess.excuteNonQuery(excuteString);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Loi Xoa Loai De Tai\n " + ex.Message);
            }
        }
    }
}
